package GoodsService

import (
	toolsDb "gdshop-back-end-go/common/db"
	"gdshop-back-end-go/common/request/BaseReq"
	"gdshop-back-end-go/common/response"
	"github.com/gogf/gf/frame/g"
	"time"

	"github.com/gogf/gf/net/ghttp"
)

func DelGoods(r *ghttp.Request, req *BaseReq.I) *response.JsonResponse {
	ctx := r.GetCtx()
	update, err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "goods_activity_goods_list").
		Where("goods_id IN (?)", req.Ids).Update(g.Map{
		"delete_at": time.Now().Unix(),
	})
	if err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}

	affected, err := update.RowsAffected()
	if err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	if affected == 0 {
		return response.FailByRequestMessage(r, "删除失败")
	}

	return response.SuccessByRequestMessage(r, "删除成功")
}
